<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="layui/common/commonHead :: commonHead(~{::title},~{},~{})">
    <title>数据字典 ADD</title>
</head>
<body>

<div class="layui-form"  lay-filter="roleAdd" id="roleAdd" style="padding: 20px 0 0 0;">

    <input type="hidden" name="parentId" th:value="${dict.id}" th:if="${type == 2}">
    <div class="layui-form-item">
        <label class="layui-form-label">字典编码</label>
        <div class="layui-input-inline">
            <input type="text" name="code" th:value="${dict.code}" disabled class="layui-input" th:if="${type == 2}">
            <input type="text" name="code"  th:if="${type == 1}"  lay-verify="required" placeholder="请输入数据字典编码(必填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" th:if="${type == 1}"   lay-verify="required" placeholder="请输入数据字典名称(必填)" autocomplete="off" class="layui-input">
            <input type="text" name="name" th:if="${type == 2}"  th:value="${dict.name}" lay-verify="required" placeholder="请输入数据字典名称(必填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">属性名称(中文)</label>
        <div class="layui-input-inline">
            <input type="text" name="titleZh" lay-verify="required"  placeholder="请输入属性名称(必填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">属性名称(英文)</label>
        <div class="layui-input-inline">
            <input type="text" name="titleEn"  placeholder="请输入属性名称(选填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">属性值</label>
        <div class="layui-input-inline">
            <input type="text" name="value"  placeholder="请输入属性值(选填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" lay-filter="sex">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="启用" checked>
            <input type="radio" name="status" value="2" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input type="text" name="remark"  placeholder="请输入备注 (选填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input class="layui-btn layui-btn-normal" type="button" lay-submit lay-filter="add" id="id-sys-dict-add-submit" value="保存">
            <input class="layui-btn layui-btn-primary" onclick="layerClose()" type="button"  lay-filter="close"  value="取消">
        </div>
    </div>
</div>

<div th:replace="layui/common/commonJs :: commonJs(~{})"></div>
<script>
    layui.use(['index', 'form'], function(){
        var $ = layui.$
            ,form = layui.form;
        //监听锁定操作
        form.on('submit(add)', function(data){
            var field = data.field;
            //提交 Ajax 成功后，静态更新表格中的数据
            $.post('/sso/admin/dict/save', field, function (data) {
                if (data.status == 200) {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
/*                    parent.layui.table.reload("dict_list_table");*/
                    parent.layui.treeGrid.reload("dict_list_table");
                    parent.layer.msg("新增成功");
                } else {
                    parent.layer.msg("添加失败请重试");
                }
            })
        });
    });
    function layerClose() {
        layui.use(['layer' ], function() {
            var layer = layui.layer;
            var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
            parent.layer.close(index);//关闭弹出层
        })
    }
</script>
</body>
</html>